#include "stdafx.h"
#include "Base.h"
#include "BaseStruct.h"
#include "User.h"
#include "UserManager.h"
#include "LoginServer.h"
#include "Packet.h"
#include "ShopManager.h"
#include "BinaryCreator.h"
#include "BinaryFactory.h"



Binary* BinaryCreator::OptionStream(options *poptions)
{
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
    *pBinary<<poptions->textdisplayspeed;
	*pBinary<<poptions->sound;
	*pBinary<<poptions->musicvolume;
	*pBinary<<poptions->soundeffectvolume;
	*pBinary<<poptions->vibration;
	*pBinary<<poptions->radarmapdisplay;
	*pBinary<<poptions->cutindisplay;
	*pBinary<<poptions->mainmenucursorposition;
	*pBinary<<(uint8)0;
	*pBinary<<poptions->camera3y;
	*pBinary<<poptions->camera3x;
	*pBinary<<poptions->camera1y;
	*pBinary<<poptions->camera1x;
	*pBinary<<poptions->controller;
	*pBinary<<poptions->weaponswap;
	*pBinary<<poptions->lockon;
	*pBinary<<poptions->brightness;
	*pBinary<<poptions->functionkeysetting;
	*pBinary<<(uint8)0;
	*pBinary<<poptions->buttondetaildisplay;
	*pBinary<<(uint32)0;


	return pBinary;
    
}

Binary* BinaryCreator::GenderStream(gender gendercode)
{
    Binary* pBinary = BinaryFactory::Instance()->Alloc();

    switch(gendercode)
	{
	case  male:
		*pBinary<<(uint8)0;
		break;
	case female:
		*pBinary<<(uint8)1;
		break;
	}


	return pBinary;
}

Binary* BinaryCreator::ClassStream(classcode charclass)
{   
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	switch(charclass)
	{
	case hunter:
		*pBinary<<(uint8)0;
		break;
	case ranger:
		*pBinary<<(uint8)1;
		break;
	case force:
		*pBinary<<(uint8)2;
		break;
	case fighgunner:
		*pBinary<<(uint8)3;
		break;
	case guntecher:
		*pBinary<<(uint8)4;
		break;
	case wartecher:
		*pBinary<<(uint8)5;
		break;
	case fortefighter:
		*pBinary<<(uint8)6;
		break;
	case fortegunner:
		*pBinary<<(uint8)7;
		break;
	case fortetecher:
		*pBinary<<(uint8)8;
		break;
	case protranser:
		*pBinary<<(uint8)9;
		break;
	case acrofighter:
		*pBinary<<(uint8)10;
		break;
	case acrotecher:
		*pBinary<<(uint8)11;
		break;
	case fighmaster:
		*pBinary<<(uint8)12;
		break;
	case gunmaster:
		*pBinary<<(uint8)13;
		break;
	case masterforce:
		*pBinary<<(uint8)14;
		break;
	case acromaster:
		*pBinary<<(uint8)15;
		break;


	}
	return pBinary;
}

Binary* BinaryCreator::RaceStream(race racecode)
{   
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	switch(racecode)
	{
	case human:
		*pBinary<<(uint8)0;
		break;
	case newman:
		*pBinary<<(uint8)1;
		break;
	case cast:
		*pBinary<<(uint8)2;
		break;
	case beast:
		*pBinary<<(uint8)3;
		break;

	}

	return pBinary;

}

Binary* BinaryCreator::SEStream()
{
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
    *pBinary<<(uint32)0;
	return pBinary;

}


Binary* BinaryCreator::AppearanceStream(appearance* pappearance,race racecode)
{

	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	switch (racecode)
	{

	case cast:
         *pBinary<<pappearance->metal_app.voicetype;
		 *pBinary<<pappearance->metal_app.voicepitch;
		 *pBinary<<(uint8)0;
		 *pBinary<<(uint8)0;
		 *pBinary<<(uint8)0;
		 *pBinary<<pappearance->metal_app.Torso;
		 *pBinary<<pappearance->metal_app.Legs;
		 *pBinary<<pappearance->metal_app.Arms;
		 *pBinary<<pappearance->metal_app.Ears;
		 *pBinary<<pappearance->metal_app.Face;
		 *pBinary<<pappearance->metal_app.HeadType;
		 *pBinary<<pappearance->metal_app.MainColor;
		 *pBinary<<(uint8)0;
		 *pBinary<<(uint8)0;
		 *pBinary<<pappearance->metal_app.lineshieldcolor;
		 *pBinary<<pappearance->metal_app.padx; 
		 *pBinary<<pappearance->metal_app.EyeBrows;
		 *pBinary<<pappearance->metal_app.Eyelashes;
		 *pBinary<<pappearance->metal_app.EyesGroup;
		 *pBinary<<pappearance->metal_app.Eyes;
		 *pBinary<<(uint8)0;
		 *pBinary<<(uint8)0;
		 *pBinary<<(uint8)0;
		 *pBinary<<pappearance->metal_app.EyesColorY;
		 *pBinary<<pappearance->metal_app.EyesColorX;
		 *pBinary<<(uint32)0;
		 *pBinary<<(uint32)0;
		 *pBinary<<(uint32)0;
		 *pBinary<<pappearance->metal_app.BodyColor;
		 *pBinary<<pappearance->metal_app.SubColor;
		 *pBinary<<pappearance->metal_app.HairStyleColorY;
		 *pBinary<<pappearance->metal_app.HairStyleColorX;
		 *pBinary<<pappearance->metal_app.Proportion;
		 *pBinary<<pappearance->metal_app.ProportionBoxX;
		 *pBinary<<pappearance->metal_app.ProportionBoxY;
		 *pBinary<<pappearance->metal_app.FaceBoxX;
		 *pBinary<<pappearance->metal_app.FaceBoxY;
		break;
	default:
		*pBinary<<pappearance->flesh_app.voicetype;
		*pBinary<<pappearance->flesh_app.voicepitch;
		*pBinary<<(uint8)0;
		*pBinary<<(uint8)0;
		*pBinary<<(uint8)0;
		*pBinary<<pappearance->flesh_app.Jacket;
		*pBinary<<pappearance->flesh_app.Pants;
		*pBinary<<pappearance->flesh_app.Shoes;
		*pBinary<<pappearance->flesh_app.Ears;
		*pBinary<<pappearance->flesh_app.Face;
		*pBinary<<pappearance->flesh_app.HairStyle;
		*pBinary<<pappearance->flesh_app.JacketColor;
		*pBinary<<pappearance->flesh_app.PantsColor;
		*pBinary<<pappearance->flesh_app.ShoesColor;
		*pBinary<<pappearance->flesh_app.LineshieldColor;
		*pBinary<<pappearance->flesh_app.Badge;
		*pBinary<<pappearance->flesh_app.EyeBrows;
		*pBinary<<pappearance->flesh_app.Eyelashes;
		*pBinary<<pappearance->flesh_app.EyesGroup;
		*pBinary<<pappearance->flesh_app.Eyes;
		*pBinary<<pappearance->flesh_app.BodySuit;
		*pBinary<<(uint8)0;
		*pBinary<<(uint8)0;
		*pBinary<<pappearance->flesh_app.EyesColorY;
		*pBinary<<pappearance->flesh_app.EyesColorX;
		*pBinary<<pappearance->flesh_app.LipsIntensity;
		*pBinary<<pappearance->flesh_app.LipsColorY;
		*pBinary<<pappearance->flesh_app.LipsColorX;
		*pBinary<<pappearance->flesh_app.SkinColor;
		*pBinary<<pappearance->flesh_app.SubColor;
		*pBinary<<pappearance->flesh_app.HairStyleColorY;
		*pBinary<<pappearance->flesh_app.HairStyleColorX;
		*pBinary<<pappearance->flesh_app.Proportion;
		*pBinary<<pappearance->flesh_app.ProportionBoxX;
		*pBinary<<pappearance->flesh_app.ProportionBoxY;
		*pBinary<<pappearance->flesh_app.FaceBoxX;
		*pBinary<<pappearance->flesh_app.FaceBoxY;
		break;
	}
	return pBinary;

}

Binary* BinaryCreator::ClassStream(chartype type)
{
	
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	Binary  BinPad;
	BinPad.BytesPad(0,20);
	switch(type)
	{
	case PC:
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x4e4f4630;
		*pBinary<<(uint32)0x08000000;
		*pBinary<<(uint32)0;
		*pBinary<<(uint32)0;
		*pBinary<<(uint32)0x4e454e44;

		break;
	case NPC:
		*pBinary<<BinPad;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		*pBinary<<(uint32)0x01000000;
		break;

	}

	return pBinary;

}


Binary* BinaryCreator::CharLevelStream(character  *pchar)
{
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	Binary* pClassStream = ClassStream(pchar->m_type);
    *pBinary<<pchar->LV;
	*pBinary<<pchar->m_attribute.blastbar;
	*pBinary<<pchar->m_attribute.luck;
	*pBinary<<(uint8)0;
	*pBinary<<(uint8)0;
	*pBinary<<(uint8)0;
	*pBinary<<(uint8)0;
	*pBinary<<(uint8)0;
	*pBinary<<pchar->EXPCurrentLevel;
	*pBinary<<(uint32)0;
	*pBinary<<pchar->m_attribute.money;
	*pBinary<<pchar->m_attribute.playtime;
	*pBinary<<*pClassStream;
	BinaryFactory::Instance()->Free(pClassStream);
	return pBinary;


}


Binary* BinaryCreator::StatsStream(stats *pstats)
{
    Binary* pBinary = BinaryFactory::Instance()->Alloc();
    *pBinary<<pstats->atp;
	*pBinary<<pstats->dfp;
	*pBinary<<pstats->ata;
	*pBinary<<pstats->evp;
	*pBinary<<pstats->sta;
	*pBinary<<(uint16)0;
	*pBinary<<pstats->tp;
	*pBinary<<pstats->mst;

	return pBinary;

}

Binary* BinaryCreator::CharPartStream(character  *pchar)
{
    
    
	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	Binary NameBin;
	NameBin.addBytes(pchar->m_name,sizeof(pchar->m_name));
	*pBinary<<NameBin;
	Binary* pRaceBin = BinaryCreator::RaceStream(pchar->m_race);
	*pBinary<<*pRaceBin;
	BinaryFactory::Instance()->Free(pRaceBin);
	Binary* pGenderBin = BinaryCreator::GenderStream(pchar->m_gender);
    *pBinary<<*pGenderBin;
	BinaryFactory::Instance()->Free(pGenderBin);
	Binary* pClassBin = BinaryCreator::ClassStream(pchar->m_type);
	*pBinary<<*pClassBin;
    BinaryFactory::Instance()->Free(pClassBin);
	Binary* pAppearanceBin = BinaryCreator::AppearanceStream(&pchar->m_appearance,pchar->m_race);
	*pBinary<<*pAppearanceBin;
	BinaryFactory::Instance()->Free(pAppearanceBin);
	Binary* pLevelsBin = BinaryCreator::CharLevelStream(pchar);
	*pBinary<<*pLevelsBin;
	BinaryFactory::Instance()->Free(pLevelsBin);


	return pBinary;
}

Binary* BinaryCreator::CharUserStream(character  *pchar)
{

	Binary* pBinary = BinaryFactory::Instance()->Alloc();
	//
    *pBinary<<pchar->TypeID;
	*pBinary<<pchar->CharGID;
	*pBinary<<(uint64)0;
	*pBinary<<pchar->CharLID;
    *pBinary<<(uint16)0;
	*pBinary<<pchar->NpcStuff;
	*pBinary<<pchar->NpcID;
	*pBinary<<pchar->QuestID;
	*pBinary<<pchar->ZoneID;
	*pBinary<<pchar->MapID;
	*pBinary<<pchar->EntryID;
	*pBinary<<(uint16)0;
	*pBinary<<(uint16)0x0100;
	*pBinary<<pchar->IntDir;
	*pBinary<<pchar->X;
	*pBinary<<pchar->Y;
	*pBinary<<pchar->Z;
	*pBinary<<(uint64)0;
	*pBinary<<pchar->PrevQuestID;
	*pBinary<<pchar->PrevZoneID;
	*pBinary<<pchar->PrevMapID;
	*pBinary<<pchar->PrevEntryID;
	Binary* pCharBin = BinaryCreator::CharPartStream(pchar);
	*pBinary<<*pCharBin;
	BinaryFactory::Instance()->Free(pCharBin);
	*pBinary<<pchar->EXPNextLevel;
	*pBinary<<pchar->EXPCurrentLevel;
	*pBinary<<pchar->MaxHP;
	Binary* pStateBin = BinaryCreator::StatsStream(&pchar->m_stats);
	*pBinary<<*pStateBin;
	*pBinary<<(uint32)0;
	Binary* pSEBin = BinaryCreator::SEStream();
	*pBinary<<*pSEBin;
	BinaryFactory::Instance()->Free(pSEBin);
	*pBinary<<(uint32)0;
	*pBinary<<pchar->LV;
	*pBinary<<*pStateBin;
	BinaryFactory::Instance()->Free(pStateBin);
	*pBinary<<pchar->CurrentHP;
	*pBinary<<pchar->MaxHP;
	Binary BinPad;
	BinPad.BytesPad(0,168);
	*pBinary<<BinPad;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint64)0;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint64)0;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint64)0;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint64)0;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0x0000803f;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
	*pBinary<<(uint32)0;
    *pBinary<<(uint32)0;
	return pBinary;

}